package com.moleq.itemsetting.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.moleq.itemsetting.adapter.AgeAdapter.ViewHolder;
import com.moleq.models.CustomerSetting;
import com.moleq.mgpos.activities.R;

public class ImportTypeAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private String[] listItem;
	private int selectedRow = 0;

	public ImportTypeAdapter(Context context, String[] listItem) {
		this.mInflater = LayoutInflater.from(context);
		this.listItem = listItem;
	}

	public void setSource(String[] listItem) {
		this.listItem = listItem;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listItem[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.customer_items, null);
			holder.tv_name = (TextView) convertView
					.findViewById(R.id.tv_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String name = listItem[position];
		holder.tv_name.setText(name);

		if (position == selectedRow) {
			holder.tv_name.setBackgroundColor(Color.rgb(255, 219, 16));
		} else {
			holder.tv_name.setBackgroundColor(Color.rgb(204, 204, 204));
		}

		return convertView;
	}

	public final class ViewHolder {
		public TextView tv_name;
	}

	public void ScrollToRow(int row) {
		selectedRow = row;
		this.notifyDataSetChanged();
	}

	public int GetSelectedIndex() {
		return selectedRow;
	}

}
